package com.baayso.bms2.user;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.baayso.bms2.core.entity.IdEntity;
import com.baayso.bms2.role.Role;

/**
 * 用户表。
 * 
 * @author ChenFangjie(2015年9月20日 上午10:59:13)
 * 
 * @since 1.0.0
 * 
 * @version 1.0.0
 * 
 */
@Entity
@Table(name = "t_user")
public class User extends IdEntity {

    private static final long serialVersionUID = -8775624596148547675L;

    // private static final Logger log = Log.get();

    /** 性别枚举 */
    public static enum Gender {
        S("未知"), M("男"), F("女");

        private Gender(String desc) {
            this.desc = desc;
        }

        private String desc;

        /** 获取描述 */
        public String getDesc() {
            return desc;
        }
    }

    @Column(name = "login_name", length = 30, nullable = false, unique = true)
    private String loginName; // 登录名
    @Column(length = 30)
    private String username; // 用户名
    @Column(length = 30)
    private String password; // 用户密码
    @Enumerated(EnumType.ORDINAL)
    private Gender gender; // 用户性别，0:保密、1:男、2:女
    @Column(length = 10)
    private String birthday; // 用户出生日期
    @Column(length = 20)
    private String tel; // 用户电话
    private String address; // 用户地址
    @Column(name = "create_time", nullable = false)
    private Long createTime; // 用户创建时间

    @ManyToMany(targetEntity = Role.class)
    @JoinTable(name = "t_role_user", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") }, inverseJoinColumns = {
            @JoinColumn(name = "role_id", referencedColumnName = "id") })
    private List<Role> roles; // 对应的角色

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

}
